const app = getApp()
 let that=this
const request = (url, options) => {
   return new Promise((resolve, reject) => {
       wx.request({
            // {app.globalData.host}为接口请求中的公共部分写在app.js中
           url: `${app.globalData.baseAPI}${url}`,
           method: options.method,
           data:  options.data ,
           header: {
            'content-type': 'application/json',
            'authorization': wx.getStorageSync('token'),
           },
           success(request) {
               if (request.data.status === 0) {
                   resolve(request.data)
               } else {
                 if(request.data.message=='身份认证失败！'){
                  wx.removeStorageSync('token');
                  wx.navigateTo({
                    url: '/pages/login/index',
                  })
                 }else{
                  reject(request.data)
                 }
               }
           },
           fail(error) {
               reject(error.data)
           }
       })
   })
}
 
const get = (url, options = {}) => {
   return request(url, { method: 'GET', data: options })
}
const post = (url, options) => {
   return request(url, { method: 'POST', data: options })
}


 
module.exports = {
   get,
   post
}